package filejoiner;

import filejoiner.data.DataSheet;
import filejoiner.data.WorkPath;
import filejoiner.io.Serializer;
import filejoiner.method.ImageShackMethod;
import filejoiner.util.DataSheetListener;
import filejoiner.util.DataSheetUtils;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;

/**
 *
 * @author Luis
 */
public class Joiner {
    
    private DataSheetUtils dataSheetUtils = new DataSheetUtils();
    private WorkPath workPath;
    
    public Joiner(DataSheetListener dataSheetListener, WorkPath workPath) {
        dataSheetUtils.addDataSheetListener(dataSheetListener);
        dataSheetUtils.addMethod(new ImageShackMethod());
        this.workPath = workPath;
    }
    
    public DataSheet upload(File file, File mask, Integer fileSize) throws FileNotFoundException, IOException, Exception {
        DataSheet dataSheet = dataSheetUtils.splitFileAndMask(file, mask, fileSize, workPath);
        dataSheetUtils.upload(dataSheet, new ImageShackMethod(), workPath);
        Serializer serializer = new Serializer(workPath.getPath(), file.getName() + ".datasheet");
        serializer.serialize(dataSheet);
        return dataSheet;
    }
    
    public DataSheet upload(DataSheet dataSheet) {
        dataSheetUtils.upload(dataSheet, new ImageShackMethod(), workPath);
        Serializer serializer = new Serializer(workPath.getPath(), dataSheet.getFileName() + ".datasheet");
        serializer.serialize(dataSheet);
        return dataSheet;
    }
    
    public void split(File file, File mask, Integer fileSize) throws FileNotFoundException, IOException, Exception {
        DataSheet dataSheet = dataSheetUtils.splitFileAndMask(file, mask, fileSize, workPath);
        Serializer serializer = new Serializer(workPath.getPath(), file.getName() + ".datasheet");
        serializer.serialize(dataSheet);
    }
    
    public void download(DataSheet dataSheet) throws Exception {
        dataSheetUtils.download(dataSheet, workPath);
        dataSheetUtils.makeFile(dataSheet, workPath);
    }
    
    public void make(DataSheet dataSheet) throws Exception {
        dataSheetUtils.makeFile(dataSheet, workPath);
    }
    
    public void clean(DataSheet dataSheet) {
        dataSheetUtils.clean(dataSheet, workPath);
    }
}
